﻿using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using Microsoft.SharePoint.Administration;
using SPContrib.Extensions;
using Microsoft.SharePoint;
using System;
using SPContrib.Artifacts.Definitions;

namespace SPContrib.Artifacts.Collections
{
    public class ModuleDefinitionCollection : IEnumerable<ModuleDefinition>
    {

        private List<ModuleDefinition> _definitions;
        private SPFeature _feature;

        public ModuleDefinitionCollection(SPFeature feature)
        {
            this._feature = feature;
            this._definitions = new List<ModuleDefinition>(
                                from definition in feature.ElementDefinitions()
                                where definition.ElementType == "Module"
                                select new ModuleDefinition(this, definition));
                                
        }

        public void Synchronize()
        {
            foreach (ModuleDefinition definition in _definitions)
            {
                definition.Synchronize();
            }
        }

        public IEnumerator<ModuleDefinition> GetEnumerator()
        {
            return _definitions.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return _definitions.GetEnumerator();
        }
    }
}
